<?php
#redis基本操作
namespace Redis;

use \Redis;

Class RedisAction
{
    private $host = "127.0.0.1";
    private $port = "6379";
    private $pwd  = "";
    public function __construct()
    {
        $this->redis = new Redis();
        $this->redis->connect($this->host,$this->port);
        $this->redis->select(2);//选择数据库2

    }
    /**
     * List操作
     * 从list头部插入一个值
     */
    public function lPush($key,$value)
    {
        $this->redis->lPush($key,$value);
    }
    #移除并返回列表的最后一个元素，若key不存在或不是列表则返回false。
    public function rPop($key)
    {
        $bool = $this->redis->rPop($key);
        return $bool;
    }
    #返回列表长度
    public function lLen($key)
    {
        $len = $this->redis->lLen($key);
        return $len;
    }

    /**
     * String操作
     * 设置字符串,新增和覆盖修改
     * @param $key  string  key
     * @param $value  string  value
     * @param $time  int  单位秒
     */
    public function setStr($key,$value,$time=null)
    {
        $bool = $this->redis->set($key,$value,$time);
        return $bool;

    }
    #获取String键值
    public function getStr($key)
    {
        $bool = $this->redis->get($key);
        return $bool;
    }
    #删除String的key
    public function delStr($key)
    {
        $bool = $this->redis->del($key);
        return $bool;
    }

}